package ooday03.homework;


public class PolymorphicDemo {
    public static void main(String[] args) {



        /*
       Master master=new Master();
       Dog dog=new Dog("小黑",5,"黑");
       Chick chick=new Chick("小白",4,"白");
       Fish  Fish=new Fish("小灰",3,"灰");
        master.feed(dog);
        master.feed(chick);
        master.feed(Fish);

         */


        Animal[]animals=new Animal[5];
        animals[0]=new Dog("小黑",3,"黑");//向上造型
        animals[1]=new Dog("小白",2,"白");
        animals[2]=new Fish("小红",4,"红");
        animals[3]=new Fish("小花",4,"花");
        animals[4]=new Chick("小灰",6,"灰");

        for(int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if(animals[i] instanceof Dog){
                Dog dog=(Dog)animals[i];
                dog.lookHome();
            }
            if(animals[i] instanceof Chick){
                Chick chick=(Chick)animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Swim){
                Swim k=(Swim)animals[i];
                k.swim();
            }
        }
    }
}
